﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using KC.Framework.Tenant;
using KC.Service.Core.Base;
using KC.DTO.Account;
using KC.DTO.Core;
using KC.Service.Core.DTO.Search;

namespace KC.Service.Core.WebApiService.Business
{
    public interface IAccountApiService
    {
        /// <summary>
        /// 获取用户登录信息
        /// </summary>
        /// <param name="userName">用户名/用户邮箱/用户手机</param>
        /// <param name="password">用户密码</param>
        /// <returns></returns>
        Task<ServiceResult<UserDTO>> TenantUserLogin(string userName, string password);

        /// <summary>
        /// 更新登录用户的OpenId
        /// </summary>
        /// <param name="userId">用户Guid</param>
        /// <param name="openId">用户的微信OpenId</param>
        /// <returns></returns>
        Task<ServiceResult<string>> UpdateUserWxOpenId(string userId, string openId);

        #region 开通服务
        Task<ServiceResult<bool>> OpenEmailService(EmailConfig config);
        Task<ServiceResult<bool>> OpenSmsService(SmsConfig config);
        Task<ServiceResult<bool>> OpenCallCenterService(CallConfig config);
        Task<bool> GetIsEnabledWorkFlow(Guid id);
        #endregion

        #region 角色信息
        /// <summary>
        /// 获取所有的角色列表
        /// </summary>
        /// <returns></returns>
        Task<List<RoleSimpleDTO>> GetAllSimpleRoles(TenantType? TenantType = null);
        /// <summary>
        /// 获取角色Id列表下的所有菜单
        /// </summary>
        /// <param name="roleIds">角色Id列表</param>
        /// <returns></returns>
        Task<List<MenuNodeSimpleDTO>> GetUserMenusByRoleIds(List<string> roleIds);
        /// <summary>
        /// 获取角色Id列表下的所有权限
        /// </summary>
        /// <param name="roleIds">角色Id列表</param>
        /// <returns></returns>
        Task<List<PermissionSimpleDTO>> GetUserPermissionsByRoleIds(List<string> roleIds);
        /// <summary>
        /// 根据角色名称列表，获取角色列表（包含所有角色的用户）
        /// </summary>
        /// <param name="roleNames">角色名称列表</param>
        /// <returns></returns>
        Task<List<RoleDTO>> GetRolesWithUsersByNames(List<string> roleNames);
        /// <summary>
        /// 获取角色的分页列表
        /// </summary>
        /// <param name="name">角色名</param>
        /// <param name="appId">应用Id</param>
        /// <param name="pageIndex">分页页码</param>
        /// <param name="pageSize">分页大小</param>
        /// <returns></returns>
        Task<PaginatedBaseDTO<RoleDTO>> GetPagenatedRolesByName(string name, string appId, int pageIndex, int pageSize);

        /// <summary>
        /// 根据角色名称，获取角色信息（包含所有角色的用户）
        /// </summary>
        /// <param name="roleName">角色名称</param>
        /// <returns></returns>
        Task<RoleDTO> GetRoleWithUsersByName(string roleName);

        /// <summary>
        /// 获取所有的权限
        /// </summary>
        /// <param name="TenantType"></param>
        /// <returns></returns>
        Task<List<PermissionSimpleDTO>> GetAllSimplePermissions(TenantType? TenantType = null);

        Task<bool> SavePermissionsAsync(List<PermissionDTO> models, Guid appGuid);

        Task<bool> SaveMenusAsync(List<MenuNodeDTO> models, Guid appGuid);
        #endregion

        #region 租户内部的员工信息
        /// <summary>
        /// 获取所有员工的简单信息
        /// </summary>
        /// <returns></returns>
        Task<List<UserDTO>> GetAllSimpleUsers();
        /// <summary>
        /// 根据用户Id列表，获取所有员工
        /// </summary>
        /// <returns></returns>
        Task<List<UserDTO>> GetAllUsersWithRolesAndOrgs();
        /// <summary>
        /// 获取该组织下的所有员工
        /// </summary>
        /// <param name="orgId">组织Id</param>
        /// <returns></returns>
        Task<List<UserDTO>> GetUsersByOrgId(int orgId);

        /// <summary>
        /// 根据用户Id列表，获取所有员工
        /// </summary>
        /// <param name="userIds">用户Id列表</param>
        /// <returns></returns>
        Task<List<UserDTO>> GetUsersByIds(List<string> userIds);

        /// <summary>
        /// 获取所有组织的下的所有员工
        /// </summary>
        /// <param name="orgIds">所有组织的Id列表</param>
        /// <returns></returns>
        Task<List<UserDTO>> GetUsersByOrgIds(List<int> orgIds);

        /// <summary>
        /// 获取所有角色的下的所有员工
        /// </summary>
        /// <param name="roleIds">所有角色的Id列表</param>
        /// <returns></returns>
        Task<List<UserDTO>> GetUsersByRoleIds(List<string> roleIds);

        /// <summary>
        /// 根据用户名列表，查询的所有员工
        /// </summary>
        /// <param name="names">用户名列表</param>
        /// <returns></returns>
        Task<List<UserDTO>> GetUsersByNames(List<string> names);

        /// <summary>
        /// 根据用户邮箱列表，查询的所有员工
        /// </summary>
        /// <param name="emails">用户邮箱列表</param>
        /// <returns></returns>
        Task<List<UserDTO>> GetUsersByEmails(List<string> emails);
        /// <summary>
        /// 获取该用户所属的所有组织信息
        /// </summary>
        /// <param name="userId">用户Guid</param>
        /// <returns></returns>
        Task<UserDTO> GetUserWithOrganizationsByUserId(string userId);

        /// <summary>
        /// 获取用户的简单数据（包含：所属的组织架构列表，不包含：系统用参数--邮箱是否确定、加密密码等等）
        /// </summary>
        /// <param name="userId">用户Guid</param>
        /// <returns></returns>
        Task<UserSimpleDTO> GetSimpleUserWithOrganizationsByUserId(string userId);
        /// <summary>
        /// 获取企业内部员工的联系方式
        /// </summary>
        /// <param name="id">用户Id</param>
        /// <returns></returns>
        //UserContactInfoDTO GetUserContactInfoById(string id);

        /// <summary>
        /// 修改租户的系统管理员的默认密码：123456
        /// </summary>
        /// <param name="password"></param>
        /// <param name="adminEmail"></param>
        /// <param name="adminPhone"></param>
        /// <returns></returns>
        Task<ServiceResult<bool>> ChangeAdminRawInfo(string password, string adminEmail, string adminPhone);

        /// <summary>
        /// 修改登录用户的密码
        /// </summary>
        /// <param name="userId">登录用户的Id</param>
        /// <param name="currentPassword">登录用户的原密码</param>
        /// <param name="newPassword">登录用户的新密码</param>
        /// <returns></returns>
        Task<ServiceResult<bool>> ChangePasswordAsync(string userId, string currentPassword, string newPassword);

        /// <summary>
        /// 验证登录用户是否存在
        /// </summary>
        /// <param name="currentUserId">登录用户的Id</param>
        /// <returns></returns>
        Task<bool> CheckChangedPwd(string currentUserId);
        /// <summary>
        /// 修改登录用户的邮箱及手机
        /// </summary>
        /// <param name="userId">登录用户的Id</param>
        /// <param name="email">登录用户的邮箱</param>
        /// <param name="phone">登录用户的手机</param>
        /// <returns></returns>
        Task<ServiceResult<bool>> ChangeMailPhoneAsync(string userId, string email, string phone);
        #endregion

        #region 组织架构及其员工
        /// <summary>
        /// 获取所有的组织架构
        /// </summary>
        /// <returns></returns>
        Task<List<OrganizationDTO>> GetAllOrganization();
        /// <summary>
        /// 获取所有的部门信息及下属员工
        /// </summary>
        /// <param name="appid">应用Id</param>
        /// <returns></returns>
        Task<List<OrganizationDTO>> GetOrganizationsWithUsers();
        /// <summary>
        /// 获取所有的部门信息（部门树：包含其下属部门）
        /// </summary>
        /// <param name="appid">应用Id，可为：Guid.Empty</param>
        /// <returns></returns>
        Task<List<OrganizationDTO>> GetRootOrganizations();

        /// <summary>
        /// 根据组织Id列表，获取所有的部门信息（部门列表，包含其下属所有的部门信息：递归查询）
        /// </summary>
        /// <param name="appid">应用Id，可为：Guid.Empty</param>
        /// <param name="ids">组织Id列表</param>
        /// <returns></returns>
        Task<List<OrganizationDTO>> GetNestOrganizationsByIds(List<int> ids);

        /// <summary>
        /// 获取所有的角色下的部门及下属员工
        /// </summary>
        /// <param name="roleIds">角色Id列表</param>
        /// <returns></returns>
        Task<List<OrganizationDTO>> GetOrganizationsWithUsersByRoleIds(List<string> roleIds);
        /// <summary>
        /// 根据用户Id，获取其所属部门及下属员工
        /// </summary>
        /// <param name="userId">用户Id</param>
        /// <returns></returns>
        Task<List<OrganizationDTO>> GetOrganizationsWithUsersByUserId(string userId);
        /// <summary>
        /// 根据部门fid获取对应下面人员
        /// </summary>
        /// <param name="orgfid"></param>
        /// <param name="appid"></param>
        /// <returns></returns>
        Task<List<OrganizationDTO>> GetUserByorgFid(Guid orgfid);
        /// <summary>
        /// 获取角色及部门下的所有部门及其下属员工
        /// </summary>
        /// <param name="searchModel">
        /// roleIds：角色Id列表
        /// depIds：部门Id列表
        /// </param>
        /// <returns></returns>
        Task<List<OrganizationDTO>> GetOrgsWithUsersByRoleIdsAndOrgids(RootOrgWithUsersSearchDTO searchModel);
        /// <summary>
        /// 获取分页的部门及其下属员工数据
        /// </summary>
        /// <param name="searchModel"></param>
        /// <returns></returns>
        Task<PaginatedBaseDTO<OrganizationDTO>> GetPaginatedOrganizationsWithUsersByFilter(
            RootOrgWithUsersPaginatedSearchDTO searchModel);



        #endregion

        /// <summary>
        /// 获取企业的UKey认证数据
        /// </summary>
        /// <param name="memberId"></param>
        /// <returns></returns>
        ServiceResult<UkeyAuthenticationDTO> GetUkeyAuthenticationByMemberId(string memberId);
    }
}
